package com.example.add8_17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.example.add8_17.adapter.Naviadapter;
import com.example.add8_17.base.BaseActivity;
import com.example.add8_17.bean.NaviBean;
import com.example.add8_17.presenter.NaviPresenter;
import com.example.add8_17.view.NaviView;

import java.util.ArrayList;

import butterknife.BindView;
import qdx.stickyheaderdecoration.NormalDecoration;

public class NaviActivity extends BaseActivity<NaviPresenter> implements NaviView {
    @BindView(R.id.navi_re)
    RecyclerView mnavi_re;
    private ArrayList<NaviBean.DataBean> dataBeans;
    private Naviadapter naviadapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mnavi_re.setLayoutManager(new LinearLayoutManager(this));
        dataBeans = new ArrayList<>();
        naviadapter = new Naviadapter(this, dataBeans);
        NormalDecoration normalDecoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return dataBeans.get(i).getName();
            }
        };
        mnavi_re.addItemDecoration(normalDecoration);
        mnavi_re.setAdapter(naviadapter);

    }

    @Override
    protected void initPresenter() {
        mPresenter=new NaviPresenter();
        mPresenter.getnavidata();
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_navi;
    }

    @Override
    public void onSuccess(NaviBean navidata) {
        dataBeans.addAll(navidata.getData());
        naviadapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
